<?php
class Order_data extends Data {
	private $alias = 'www-yueshihui-com';
	private $tb = 'order';
	private $cols = array('id', 'oid', 'product_id', 'ticket_id', 'price', 'num', 'uid', 'status', 'name', 'tellphone', 'gp', 'gt', 'gc', 'location', 'post', 'receiver', 'receive_mode', 'receive_comment', 'coupon', 'created_time');
	
	/**
	 * 产生不重复的oid
	 */
	public function oid($uid) {
		return date('Ymd') . str_pad(mt_rand(1, 99999), 5, '0', STR_PAD_LEFT) . str_pad(mt_rand(1, 99999), 5, '0', STR_PAD_LEFT); 
	}
	/**
	 * 添加订单
	 * @param unknown_type $cols
	 */
	public function add($cols) {
		if(!($db = $this->connect($this->alias))) return false;
		
		if($db->insert($this->tb, $cols)) return $db->lastInsertId();
		else return false;
	}
	/**
	 * 获取订单数量
	 * @param unknown_type $params
	 */
	public function count($params = array()) {
		if(!($db = $this->connect($this->alias))) return false;
		
		return $db->count($this->tb, $params);
	}
	/**
	 * 分页获取订单信息
	 * @param unknown_type $page
	 * @param unknown_type $size
	 * @param unknown_type $params
	 * @param unknown_type $orderBy
	 */
	public function page($page, $size, $params = array(), $orderBy = '`id` DESC') {
		if(!($db = $this->connect($this->alias))) return false;
		
		return $db->page($this->tb, $this->cols, $params, $orderBy, $page, $size);
	}
}